package com.vn.ld.order.domain.queue.manager;

import java.util.Queue;
import java.util.concurrent.BlockingQueue;

import com.vn.ld.order.domain.ModifiedDBObject;

public class DbQueueManager implements Runnable {
	
	private BlockingQueue<Queue<ModifiedDBObject>> dbQueue;
	
	public DbQueueManager(BlockingQueue<Queue<ModifiedDBObject>> dbQueue) {
		this.dbQueue = dbQueue;
	}
	
	@Override
	public void run() {
		
		//take from queue
		Queue<ModifiedDBObject> oneTransactionQueue = null;
		try {
			oneTransactionQueue = dbQueue.take();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		//TODO in one transaction
		for (ModifiedDBObject modifiedDBObject : oneTransactionQueue) {
			
			switch(modifiedDBObject.getModificationType()){
				case ADD: insertToDb(modifiedDBObject); 
				case DELETE: ;
				case UPDATE: ;
			}
					
		}
		
	}
	
	protected void insertToDb(ModifiedDBObject modifiedDBObject){
		//TODO
	};

	protected void deleteFromDb(ModifiedDBObject modifiedDBObject){
		//TODO
	};
	
	protected void saveToDb(ModifiedDBObject modifiedDBObject){
		//TODO
	};
}
